﻿using System;
using System.Windows.Forms;

namespace win_auto_login
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string aaa="sjdkfjakjdjfakskdfas";

            if ("sdfdfa" == "sdfasdf") { } else { }


            //设置系统磁盘autorun.inf是否执行
            string key = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon";
            Microsoft.Win32.RegistryKey MyReg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(key, true);
            if (MyReg == null)
            {//如果子键节点不存在，则创建之
                MyReg = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(key);
            }
            if (checkBox1.Checked == true)
            {
                MyReg.SetValue("Defaultusername", tb_name.Text);  //子项中添加键值对
                MyReg.SetValue("Defaultpassword", tb_pass.Text);  //子项中添加键值对
                MyReg.SetValue("Autoadminlogon", "1");  //子项中添加键值对
            }
            else
                MyReg.SetValue("autoadminlogon", "1");   //子项中添加键值对

            MessageBox.Show("更改成功！");

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //设置系统磁盘autorun.inf是否执行
            string key = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon";
            Microsoft.Win32.RegistryKey MyReg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(key, true);
            if (MyReg == null)
            {//如果子键节点不存在，则创建之
                MyReg = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(key);
            }
            try
            {
                if (MyReg.GetValue("Autoadminlogon").ToString() == "1") { checkBox1.Checked = true; }
                tb_name.Text = MyReg.GetValue("Defaultusername").ToString();
                tb_pass.Text = MyReg.GetValue("Defaultpassword").ToString();
            }
            catch { }

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked == true)
            {
                tb_pass.PasswordChar = '\0';

            }else
                tb_pass.PasswordChar = '*';
        }
    }
}
